﻿#include "PlatformProperty.h"

MAPPING_VALUE(sdb::AvailabilitySts, PropertyStatus, PropertyStatus::NotAvailable)
    MAPPING_ITEM(sdb::AvailabilitySts::Active, PropertyStatus::Active)
    MAPPING_ITEM(sdb::AvailabilitySts::NotActive, PropertyStatus::NotActive)
    MAPPING_ITEM(sdb::AvailabilitySts::Error, PropertyStatus::Error)
    MAPPING_ITEM(sdb::AvailabilitySts::NotAvailable, PropertyStatus::NotAvailable)
MAPPING_END

SYSTEM_READ_WRITE_PROPERTY(HVAC_ELECTRIC_DEFROSTER_ON, bool) {
    builder.area(VehicleAreaWindow::FRONT_WINDSHIELD)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                                     sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(
                                             SIGNAL.getPA_CL_FrontDefrost().availability);
                                     PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                                     VHALOG.d("HVAC_ELECTRIC_DEFROSTER_ON FRONT_WINDSHIELD status changed to: %d ", status);
                                     return status;
                                 }, PASignal::PA_CL_FrontDefrost)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                auto data = SIGNAL.getPA_CL_FrontDefrost().data;
                VHALOG.d("HVAC_ELECTRIC_DEFROSTER_ON FRONT_WINDSHIELD value changed to: %d ", data);
                if ((sdb::ElecDefrostSts)data == sdb::ElecDefrostSts::On || (sdb::ElecDefrostSts)data == sdb::ElecDefrostSts::Auto) {
                    return true;
                } else {
                    return false;
                }
            }, PASignal::PA_CL_FrontDefrost)
            .onSetProperty([](const bool &value) {
                VHALOG.d("halOnSetProperty HVAC_ELECTRIC_DEFROSTER_ON front: %d", value);
                SIGNAL.setCB_CL_FrontDefrost(value ? sdb::ElecDefrostSts::On : sdb::ElecDefrostSts::Off);
            })
            .area(VehicleAreaWindow::REAR_WINDSHIELD)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                                     sdb::AvailabilitySts rearStatus = sdb::AvailabilitySts(SIGNAL.getPA_CL_RearDefrost().availability);
                                     VHALOG.d("HVAC_ELECTRIC_DEFROSTER_ON rearStatus: %d", rearStatus);
                                     return mappingValue(rearStatus, PropertyStatus::NotAvailable);
                                 },
                                 PASignal::PA_CL_RearDefrost)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                auto data = SIGNAL.getPA_CL_RearDefrost().data;
                VHALOG.d("HVAC_ELECTRIC_DEFROSTER_ON REAR_WINDSHIELD value changed to: %d ", data);
                if ((sdb::ElecDefrostSts)data == sdb::ElecDefrostSts::On || (sdb::ElecDefrostSts)data == sdb::ElecDefrostSts::Auto) {
                    return true;
                } else {
                    return false;
                }
            }, PASignal::PA_CL_RearDefrost)
            .onSetProperty([](const bool value) {
                VHALOG.d("halOnSetProperty HVAC_ELECTRIC_DEFROSTER_ON rear: %d", value);
                SIGNAL.setCB_CL_RearDefrost(value ? sdb::ElecDefrostSts::On : sdb::ElecDefrostSts::Off);
            });
}
